import request from "@/utils/request";
import { Form } from "@/views/login/login.vue";

// 户籍管理
// 查询列表
export interface SearchParams {
    pageNo: number;
    pageSize: number;
    name: string;
    residentRegistryAddress: string;
    idNumber: string;
}
// 列表参数
export interface TableItem {
    age: number | string;
    familyId: string;
    householder: boolean;
    id: string;
    idNumber: string;
    name: string;
    phone: string;
    profession: string;
    relationshipWithHouseholder: null | string;
    resideAddress: string;
    residentRegistryAddress: string;
    sex: number | string;
}
export interface ResTable {
    total?: number,
    code: number,
    data: TableItem
}
// 添加户主信息
export interface HostInfo {
    name: string;
    sex: number | string;
    age: number | string;
    idNumber: string;
    phone: string;
    resideAddress: string;
    residentRegistryAddress: string;
    profession: string;
    relationshipWithHouseholder: null | string; // new 添加家庭成员
    familyId: string; // new 添加家庭成员
}


// 登录
export function loginApi(params: Form) {
    return request({
        url: '/login',
        method: 'post',
        data: params,
    })
}
// 查看当前用户信息
export function findCurrentUser() {
    return request({
        url: '/findCurrentAccount',
        method: 'get',
    })
}
// 注销当前用户账号
export function deleteCurrentUser(data: { id: string }) {
    return request({
        url: '/delMyAcc',
        method: 'post',
        data
    })
}
// 退出当前用户账号
export function loginOutCurrentUser() {
    return request({
        url: '/logout',
        method: 'get',
    })
}

// 查看航班信息全部成员
export function findMember(params: Partial<SearchParams>) {
    return request<ResTable>({
        url: '/findMember',
        method: 'post',
        data: params,
    })
}

// 查看航班信息成员详情
export function findResidentRegistry(params: { id: string }) {
    return request<ResTable>({
        url: '/findResidentRegistry',
        method: 'post',
        data: params,
    })
}

// 添加户主
export function addHouseholder(params: Partial<HostInfo>) {
    return request({
        url: '/addHouseholder',
        method: 'post',
        data: params,
    })
}

// 编辑户主
export function modifyMember(params: Partial<HostInfo>) {
    return request({
        url: '/modifyMember',
        method: 'post',
        data: params,
    })
}

// 添加家庭成员
export function addFamilyMember(params: Partial<HostInfo>) {
    return request({
        url: '/addFamilyMember',
        method: 'post',
        data: params,
    })
}

// 查看家庭成员
export function findFamilyAllMember(params: { familyId: string }) {
    return request({
        url: '/findFamilyAllMember',
        method: 'post',
        data: params,
    })
}

// 删除户主
export function removeResidentRegistry(params: { id: string }) {
    return request({
        url: '/removeResidentRegistry',
        method: 'post',
        data: params,
    })
}